home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBDisplay.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.6 KB  |  103 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBDisplay([leftCol,topRow,rightCol,bottomRow]) -- Return the current terminal emulator display.
  3.         If the rows and columns parameters are present, only return that rectangle of the display.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBDisplay.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=2756 -sn Main=CTBDisplay ∂
  9.             CTBDisplay.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBDisplay }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBDisplay(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBDisplay(paramPtr);
  36.     end;
  37.  
  38. procedure CTBDisplay(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var i: integer;
  43.         theEnvirons: TermEnvironRec;
  44.         sel: TMSelection;
  45.         h: Handle;
  46.         p: Ptr;
  47.         l: longInt;
  48.         t: ResType;
  49.  
  50.     procedure Fail(errMsg: Str255); { set theResult and quit }
  51.         begin
  52.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  53.             exit(CTBDisplay);
  54.         end;
  55.  
  56.     begin
  57.         { Check the parameter count. }
  58.         i := paramPtr^.paramCount;
  59.         if (i <> 0) and (i <> 4) then Fail('Invalid parameter count');
  60.  
  61.         { Check that the Comm Toolbox is available. }
  62.         CTBReady;
  63.         { And a terminal tool is also present. }
  64.         EnsurePresent(terminalTool);
  65.  
  66.         { Get the screen rectangle to retrieve. }
  67.         theEnvirons.version := curTermEnvRecVers;
  68.         FailOSErr(TMGetTermEnvirons(Globals^^.termHand,theEnvirons));
  69.         with sel.selRect do
  70.             begin
  71.                 top := 1;
  72.                 left := 1;
  73.                 bottom := theEnvirons.textRows;
  74.                 right := theEnvirons.textCols;
  75.                 if ParmPresent(1) and ParmPresent(2) and ParmPresent(3) and ParmPresent(4) then
  76.                     begin
  77.                         l := GetLongParm(1); if l > 1 then left := l;
  78.                         l := GetLongParm(2); if l > 1 then top := l;
  79.                         l := GetLongParm(3); if l < right then right := l;
  80.                         l := GetLongParm(4); if l < bottom then bottom := l;
  81.                     end;
  82.             end;
  83.  
  84.         { Do a set selection/get selection. }
  85.         TMSetSelection(Globals^^.termHand,sel,selTextBoxed);
  86.         h := NewHandle(0);
  87.         if h = nil then Fail('Could not allocate handle');
  88.         l := TMGetSelect(Globals^^.termHand,h,t);
  89.         { If we got something, then return it as a regular HyperCard string. }
  90.         if (l >= 0) and (t = 'TEXT') then
  91.             begin
  92.                 l := GetHandleSize(h);
  93.                 SetHandleSize(h,l+1);
  94.                 p := Ptr(ord4(h^)+l);
  95.                 p^ := 0;
  96.                 paramPtr^.returnValue := h
  97.             end
  98.         { Otherwise forget it. }
  99.         else DisposHandle(h);
  100.     end;
  101.  
  102. end.
  103.